package com.airsaid.pickerviewlibrary;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.airsaid.pickerviewlibrary.widget.BasePickerView;
import java.util.ArrayList;

/**
 * 选择生肖
 *
 * @author yxj on 2022/7/11
 */
public class ChoiceItemView extends BasePickerView implements View.OnClickListener{

    private Button mBtnSubmit, mBtnCancel;
    private TextView mTxtTitle;
    private View mHeadView;

    private ChoiceItemWheel wheel ;


    public ChoiceItemView(Context context) {
        super(context);
        initView(context);
    }


    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.chinese_zodiac_layout,contentContainer);
        wheel = new ChoiceItemWheel(findViewById(R.id.mWheelView));
        mHeadView = findViewById(R.id.rlt_head_view);
        mTxtTitle = (TextView) findViewById(R.id.tvTitle);
        mBtnSubmit = (Button) findViewById(R.id.btnSubmit);
        mBtnCancel = (Button) findViewById(R.id.btnCancel);
        mBtnSubmit.setOnClickListener(this);
        mBtnCancel.setOnClickListener(this);
    }


    /**
     */
    public <T> void setData(ArrayList<T> list){
        wheel.setData(list);
    }



    /**
     * 设置头部背景颜色
     */
    public void setHeadBackgroundColor(int color){
        mHeadView.setBackgroundColor(color);
    }

    /**
     * 设置标题
     */
    public void setTitle(String title){
        mTxtTitle.setText(title);
    }

    /**
     * 设置标题颜色
     */
    public void setTitleColor(int resId){
        mTxtTitle.setTextColor(resId);
    }

    /**
     * 设置标题大小
     */
    public void setTitleSize(float size){
        mTxtTitle.setTextSize(size);
    }

    /**
     * 设置取消文字
     */
    public void setCancelText(String text){
        mBtnCancel.setText(text);
    }

    /**
     * 设置取消文字颜色
     */
    public void setCancelTextColor(int resId){
        mBtnCancel.setTextColor(resId);
    }

    /**
     * 设置取消文字大小
     */
    public void setCancelTextSize(float size){
        mBtnCancel.setTextSize(size);
    }

    /**
     * 设置确认文字
     */
    public void setSubmitText(String text){
        mBtnSubmit.setText(text);
    }

    /**
     * 设置确认文字颜色
     */
    public void setSubmitTextColor(int resId){
        mBtnSubmit.setTextColor(resId);
    }

    /**
     * 设置确认文字大小
     */
    public void setSubmitTextSize(float size){
        mBtnSubmit.setTextSize(size);
    }

    /**
     * 设置滚动文字大小
     */
    public void setTextSize(float size){
        wheel.setTextSize(size);
    }



    @Override
    public void onClick(View v) {
        int id = v.getId();
        if(id == R.id.btnSubmit){
            if(onChoiceSelectListener != null){
                onChoiceSelectListener.onChoicesSelect(wheel.getCurrentItems());
            }
            dismiss();
        }else if(id == R.id.btnCancel){
            dismiss();
        }
    }


    public interface OnChoiceSelectListener {
        void onChoicesSelect(int option1);
    }

    OnChoiceSelectListener onChoiceSelectListener ;
    public void setOnChoiceSelectListener(OnChoiceSelectListener onChoiceSelectListener) {
        this.onChoiceSelectListener = onChoiceSelectListener;
    }
}
